package com.ate.ui.fragments;


import android.app.ProgressDialog;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.ate.adapters.ClassLeftRecyAdapter;
import com.ate.adapters.ClassRightRecyAdapter;
import com.ate.javamvp.R;
import com.ate.bean.GoodsBean;
import com.ate.bean.SearchBean;
import com.ate.bean.TypeBean;
import com.ate.javamvp.mvp.contract.Contract;
import com.ate.javamvp.mvp.presenter.DataPresneter;
import com.ate.lib_core.http.mvp.view.BaseFragment;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.google.android.material.textfield.TextInputEditText;

import java.util.ArrayList;
import java.util.List;


public class ClassifyFragment extends BaseFragment implements Contract.DataXiaView {

    private TextInputEditText edit;
    private RecyclerView leftRecy;
    private RecyclerView rightRecy;
    private List<TypeBean> list_string;
    private ClassLeftRecyAdapter classLeftRecyAdapter;

    private DataPresneter dataPresneter;
    private ClassRightRecyAdapter adapter;

    @Override
    public int bandlayout() {
        return R.layout.fragment_classify;
    }

    @Override
    public void initView() {
        edit = (TextInputEditText) findViewById(R.id.edit);
        leftRecy = (RecyclerView) findViewById(R.id.left_recy);
        rightRecy = (RecyclerView) findViewById(R.id.right_recy);
        addRecy();
    }

    private void addRecy() {
        list_string = new ArrayList<>();
        list_string.add(new TypeBean("男装",true));
        list_string.add(new TypeBean("上装",false));
        list_string.add(new TypeBean("球鞋",false));
        list_string.add(new TypeBean("女装",false));
        list_string.add(new TypeBean("高街",false));
        list_string.add(new TypeBean("服配",false));
        list_string.add(new TypeBean("包类",false));
        list_string.add(new TypeBean("美妆",false));
        list_string.add(new TypeBean("生活",false));
        list_string.add(new TypeBean("数码",false));
        list_string.add(new TypeBean("潮玩",false));
        list_string.add(new TypeBean("潮童",false));
        list_string.add(new TypeBean("好物",false));



        classLeftRecyAdapter = new ClassLeftRecyAdapter(R.layout.classify_leftrecy, list_string);
        leftRecy.setAdapter(classLeftRecyAdapter);
        leftRecy.setLayoutManager(new LinearLayoutManager(getContext()));
        classLeftRecyAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                for (TypeBean typeBean : list_string) {
                    typeBean.setChecked(false);
                }
                list_string.get(position).setChecked(true);
                classLeftRecyAdapter.notifyDataSetChanged();
                dataPresneter.getSearchGoods(list_string.get(position).getName(),"");
                adapter.notifyDataSetChanged();
                showLoading();
            }
        });

    }
    ProgressDialog dialog;
    @Override
    public void showLoading() {
        super.showLoading();
        dialog = new ProgressDialog(getContext());
        dialog.setTitle("拼命加载中T^T");
        dialog.setMessage("请稍后...");
        dialog.show();
    }

    @Override
    public void hideLoading() {
        super.hideLoading();
        if (dialog!=null)
        dialog.dismiss();
    }

    @Override
    public void initData() {
        dataPresneter = new DataPresneter(this);
        dataPresneter.getSearchGoods("男装","");
    }

    @Override
    public void onSuccess(List<GoodsBean.DataBean> data) {

    }

    @Override
    public void onFail() {

    }

    @Override
    public void onSucc(List<SearchBean.DataBean> data) {
        adapter = new ClassRightRecyAdapter(R.layout.classright_layout, data);
        rightRecy.setAdapter(adapter);
        rightRecy.setLayoutManager(new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL));
    }
}